iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 30
0
自我挑戰組

各種筆記系列 第 30

[Kata] Clojure - Day 30

  • 分享至 

  • xImage
  •  

Responsible Drinking

Codewars Bar recommends you drink 1 glass of water per standard drink so you're not hungover tomorrow morning.

Your fellow coders have bought you several drinks tonight in the form of a string. Return a string suggesting how many glasses of water you should drink to not be hungover.

記算字串中總共有多少杯酒,回傳相同數量的水

Example

"1 beer"  =>  "1 glass of water"
"1 shot, 5 beers and 1 glass of wine"  =>  "7 glasses of water"

Solution

 (ns hydrate)
(defn hydrate [drink-string]
  (def glasses (apply + (map #(Integer/parseInt (str %)) (filter #(Character/isDigit %) drink-string))))
 (str glasses (if (= glasses 1) " glass of water" " glasses of water"))
)

上一篇
[Kata] Clojure - Day 29
系列文
各種筆記30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言